﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class UpperCaseTags
{
    static void TextToUpperCase(StringBuilder text, int startIndex, int lastIndex)
    {

        for (int index = startIndex; index < lastIndex; index++)
        {
            if (char.IsLower(text[index]))
            {
                text[index] = char.ToUpper(text[index]);
            }
        }
    }

    static void Main()
    {
        string text = "We are living in a <upcase>yellow submarine</upcase>. We don't have <upcase>anything</upcase> else.";//Console.ReadLine();
        StringBuilder processText = new StringBuilder(text);
        int startIndex = new int();
        int lastIndex = new int();
        bool isStartIndex = false;
        bool isLastIndex = false;
        bool isValid = true;
        string openTag = "<upcase>";
        string closeTag = "</upcase>";

        for (int index = 0; index < text.Length; index++)
        {
            if (isStartIndex == false)
            {
                int indexFount = text.IndexOf(openTag, index);
                if (indexFount != -1)
                {
                    startIndex = indexFount;
                    index = indexFount;
                    isStartIndex = true;
                }
            }

            if (isLastIndex == false)
            {
                int indexFount = text.IndexOf(closeTag, index);
                if (indexFount != -1)
                {
                    lastIndex = indexFount;
                    index = indexFount + 1;
                    isLastIndex = true;
                }
            }

            if (isLastIndex && !isStartIndex)
            {
                isValid = false;
                break;
            }
            else if (isStartIndex && isStartIndex)
            {
                TextToUpperCase(processText, startIndex, lastIndex);
                processText.Remove(startIndex, openTag.Length);//remove open tag, e.g. <upcase>
                processText.Remove(lastIndex - openTag.Length, closeTag.Length);//remoce closetad, e.g. </upcase>
                text = processText.ToString();
                index = startIndex;
                isLastIndex = false;
                isStartIndex = false;
            }
            else if(!isStartIndex && !isLastIndex)
            {
                break;
            }
            
        }

        if (isValid)
        {
            Console.WriteLine(processText);
        }
        else
        {
            Console.WriteLine("Please enter valid text");
        }
    }
}

